import pandas_datareader.data as web
import datetime
import pandas as pd

import matplotlib.pyplot as plt

# df_stockload = web.DataReader("000001.SS", "yahoo", datetime.datetime(2019,1,1), datetime.date.today())

#print(df_stockload.describe)

#绘制移动平均线
# df_stockload.Close.plot(c='b')
# df_stockload.Close.rolling(window=30).mean().plot(c='r') #pd.rolling_mean(df_stockload.Close,window=30).plot(c='r')
# df_stockload.Close.rolling(window=60).mean().plot(c='g') #pd.rolling_mean(df_stockload.Close,window=60).plot(c='g')
# plt.legend(['Close','30ave','60ave'],loc='best')
# plt.show()

stock_code = input("美股直接输入股票代码如GOOG \n港股输入代码+对应股市，如腾讯：0700.hk \n国内股票需要区分上证和深证，股票代码后面加.ss或者.sz\n请输入你要查询的股票代码：")
start_date = "2000-11-01"
end_date = "2018-11-01"
stock_info = data.get_data_yahoo(stock_code, start_date, end_date)
# 展示前5行
print(stock_info.head())
# print(stock_info.info())
#  保存为Excel文件和CSV文件
stock_info.to_excel('%s.xlsx'%stock_code)
stock_info.to_csv('%s.csv'%stock_code)
# 输出图表
plt.plot(stock_info['Close'], 'g')
plt.show()